#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      mcorrea
#
# Created:     24/04/2012
# Copyright:   (c) mcorrea 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------

class Set:
    def __init__(self, values=[]):
        self.data = []
        self.concat(values)

    def intersect(self, other):
        res = []
        for x in self.data:
            if x in other:
                res.append(x)
        return Set(res)

    def union(self, other):
        res = self.data
        for x in other:
            if not x in res:
                res.append(x)
        return Set(res)

    def concat(self, values):
        for x in values:
            if not x in self.data:
                self.data.append(x)

    def __len__(self):
        return len(self.data)

    def __getitem__(self, key):
        return self.data[key]

    def __and__(self, other):
        return self.intersect(other)

    def __or__(self, other):
        return self.union(other)

    def __repr__(self):
        return 'Set('+repr(self.data)+')'

def main():
    x = Set("abcda")
    print x
    y = Set("yzab")
    print x & y
    print x | y



if __name__ == '__main__':
    main()
